package com.wanshi.blog.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.wanshi.blog.article.mapper.CategoryMapper;
import com.wanshi.blog.article.req.CategoryREQ;
import com.wanshi.blog.article.service.ICategoryService;
import com.wanshi.blog.entity.Category;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanshi.blog.util.enums.Result;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 文章分类表 服务实现类
 * </p>
 *
 * @author 顽石教育-www.wanshi.com
 * @since 2021-09-07
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {

    @Override
    public Result queryPage(CategoryREQ req) {
        QueryWrapper<Category> wrapper = new QueryWrapper();

        if(req.getStatus() != null) {
            wrapper.eq("status", req.getStatus());

        }if(StringUtils.isNotBlank(req.getName())) {
            wrapper.like("name", req.getName());
        }
        wrapper.orderByDesc("status").orderByAsc("sort");

        return Result.ok(baseMapper.selectPage(req.getPage(), wrapper));
    }
}
